package com.sunday.boot3.user.center.rest.api.impl;

import com.sunday.common.core.converter.MapperConvert;
import com.sunday.common.core.remoting.rest.annotation.VoErrorShowType;
import com.sunday.common.core.remoting.rest.page.PageVO;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import com.sunday.boot3.user.center.controller.RolePermissionsController;
import com.sunday.boot3.user.center.pojo.dto.role.permissions.PageRolePermissionsReqDTO;
import com.sunday.boot3.user.center.pojo.dto.role.permissions.SaveRolePermissionsReqDTO;
import com.sunday.boot3.user.center.pojo.dto.role.permissions.UpdateRolePermissionsReqDTO;
import com.sunday.boot3.user.center.pojo.dto.role.permissions.RemoveRolePermissionsReqDTO;
import com.sunday.boot3.user.center.rest.vo.role.permissions.PageRolePermissionsResVO;
import com.sunday.boot3.user.center.rest.vo.role.permissions.SaveRolePermissionsReqVO;
import com.sunday.boot3.user.center.rest.vo.role.permissions.PageRolePermissionsReqVO;
import com.sunday.boot3.user.center.rest.vo.role.permissions.RemoveRolePermissionsReqVO;
import com.sunday.boot3.user.center.rest.vo.role.permissions.UpdateRolePermissionsReqVO;
import com.sunday.boot3.user.center.rest.api.RolePermissionsApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 角色权限关系表 Web impl 层
 * @author: zsy
 * @Create: 2024/09/22 16:24:39
 */
@Slf4j
@RestController
@RequestMapping(RolePermissionsApi.ACCESS_PATH)
@RequiredArgsConstructor
public class RolePermissionsApiImpl implements RolePermissionsApi {

    private final RolePermissionsController rolePermissionsController;

    /**
     * @Description: 新增 角色权限关系表 数据
     * @Param: [saveRolePermissionsReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse save(SaveRolePermissionsReqVO saveRolePermissionsReqVO) {
        return RestResponse.resultReturn(rolePermissionsController.save(MapperConvert.map(saveRolePermissionsReqVO, SaveRolePermissionsReqDTO.class)));
    }

    /**
     * @Description: 删除 角色权限关系表 数据
     * @Param: [removeRolePermissionsReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse remove(RemoveRolePermissionsReqVO removeRolePermissionsReqVO) {
        return RestResponse.resultReturn(rolePermissionsController.remove(MapperConvert.map(removeRolePermissionsReqVO, RemoveRolePermissionsReqDTO.class)));
    }

    /**
     * @Description: 修改 角色权限关系表 数据
     *
     * @Param: [updateRolePermissionsReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse update(UpdateRolePermissionsReqVO updateRolePermissionsReqVO) {
        return RestResponse.resultReturn(rolePermissionsController.update(MapperConvert.map(updateRolePermissionsReqVO, UpdateRolePermissionsReqDTO.class)));
    }

    /**
    * @Description: 获取 角色权限关系表 分页列表数据
    *
    * @Param: [pageRolePermissionsReqVO]
    * @Return: com.sunday.common.core.remoting.rest.response.RestResponse<com.sunday.common.core.remoting.rest.page.fegin.FeginPageResultVO<com.sunday.boot3.user.center.rest.vo.role.permissions.PageRolePermissionsResVO>>
    * @author: zsy
    * @Create: 2024/09/22 16:24:39
    */
    @Override
    @VoErrorShowType(RestResponse.ShowTypeEnum.NOTIFICATION)
    public RestResponse<PageVO<PageRolePermissionsResVO>> page(PageRolePermissionsReqVO pageRolePermissionsReqVO) {
        return RestResponse.convertResultReturn(
                rolePermissionsController.page(MapperConvert.map(pageRolePermissionsReqVO, PageRolePermissionsReqDTO.class)),
                body -> PageVO.of(body, PageRolePermissionsResVO.class));
    }

}